<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>留言板案例</title>
</head>
<body>
    <div id="app">
        <div>
            <div>
                <label for="author">发布者：</label>
                <input type="text" v-model="author" id="author">
            </div>
            <div>
                <label for="content">内容：</label>
                <input type="text" v-model="content" id="content">
            </div>
            <button @click="publish">留言</button>
        </div>
        <msg-list :list="msgs"></msg-list>
    </div>

    <template id="temp">
        <div>
            <ul>
                <li v-for="item in list" :key="item.id">
                    <p><span>留言人：</span>{{item.author}}</p>
                    <p><span>留言内容：</span>{{item.content}}</p>
                </li>
            </ul>
        </div>
    </template>
</body>
<script src="../../vue文件/vue.js"></script>
<script >

    Vue.component('msgList',{
        template:'#temp',
        props:{
            list:{
                type:Array
            }
        }
    })
    

        let vm = new Vue({
            el: '#app',
            data: {
                 author:'',
                 content:'',
                 msgs:[
                   {id:1,author:'张三',content:'老师真帅。。。'},
                   {id:2,author:'李四',content:'你真帅。。。'},
                   {id:3,author:'王五',content:'我太帅了。。。'}
                   ]
            },
            methods: {
                publish(){
                    this.msgs.unshift({
                        id:this.msgs.length+1,
                        author:this.author,
                        content:this.content
                    })
                }
            }
        })
</script>
</html>